package com.westmarine.qr_hybris.tests;

import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.assertEquals;

import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
import org.monte.media.math.Rational;
import org.monte.media.Format;
import org.monte.screenrecorder.ScreenRecorder;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import static org.monte.media.AudioFormatKeys.*;
import static org.monte.media.VideoFormatKeys.*;


import com.westmarine.qr_hybris.util.Browser;
import com.westmarine.qr_hybris.util.Browser.DriverType;
import com.westmarine.qr_hybris.util.MethodAction.CardType;
import com.westmarine.qr_hybris.util.MethodAction;
import com.westmarine.qr_hybris.util.MethodUtil;

public class BugQAVN {
	private ScreenRecorder screenRecorder;
	private WebDriver driver;
	private String emailAddress="vun";
    private String googlemail = "@westmarine.com";
    public Select selectAddress;
    public Select selectState;
    public Select selectCard;
    public Select selectMonth;
    public Select selectYear;
    public Select selectCountry;
    public Select selectStore;
    public WebElement myWait;
    public WebElement search;
    public String mainUrl="http://qr-hybris.westmarine.net/";
    public String username="vun@westmarine.com";
    public String password="Ilove12345678";
    
	
	@BeforeMethod
	public void beforeMethod() throws IOException, AWTException {
		Browser.setDriver(DriverType.CHROME);
		Browser.driver.manage().window().maximize();
		driver = Browser.driver;
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		screenRecorder = MethodUtil.getScreenRecorder();
		screenRecorder.start();
	}
	
	@Test
	public void WMAR_7455(){
		//apparel sku = 8111312
		String actualResult1 = MethodAction.getQuantityOfSku(driver, "8111312");
		assertEquals("",actualResult1); 
		//bachelor sku = 4235750
		String actualResult2 = MethodAction.getQuantityOfSku(driver, "4235750");
		assertEquals("",actualResult2);
	}
	
	@Test
	public void WMAR_7245() throws InterruptedException{
		//apparel sku = 8111312
		MethodAction.searchSkuAddToCartBachelorGoToCartGoToCheckout(driver, "4235750");
		MethodAction.loginAsReturnCustomer(driver, username, password);
		MethodAction.deliveryShippingAddressFreightForwardAddressClick(driver);
		Thread.sleep(1500);
		MethodAction.deliveryShippingAddreesEnterFreightForwardAddress(driver, "BN", "Prodigious", 
							"United States", "firstName", "lastName", "line1", "", "Milpitas",
							"California", "95035", "", 
							"United States", "Vu", "destinationLastName",
							"destinationLine1", "", "", "California", "94539", "8607965308");
		String expectedResult = driver.findElements(By.name("townCity")).get(1).getAttribute("value");
		MethodAction.deliveryShippingAddressContinueClick(driver);
		String actualResult = driver.findElements(By.name("townCity")).get(1).getAttribute("value");
		assertEquals(expectedResult, actualResult);
		System.out.println(expectedResult);
		System.out.println(actualResult);
	}
	
	@Test
	public void WMAR_7144() throws IOException{
		//Duplicate CSS reference negatively affecting AB Testing.
		URL obj = new URL(mainUrl);
		int changesCssNumber = 0;
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
		con.setRequestMethod("GET");
		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'GET' request to URL : " + mainUrl);
		System.out.println("Response Code : " + responseCode);
		BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()));
		String inputLine;
		StringBuffer response = new StringBuffer();
		while ((inputLine = in.readLine()) != null) {
			response.append(inputLine);
			if (inputLine.contains("changes.css")){
				changesCssNumber++;
			}
		}
		in.close();
		System.out.println(response.toString());
		System.out.println(changesCssNumber);
		assertEquals(1, changesCssNumber);
	}
	
	
	@AfterMethod
	public void afterMethod() throws IOException, AWTException{
		//Browser.driver.close();
		screenRecorder.stop();
	}

 
}


	   

